<?php
/**
 * Free Uch Web BootStrap
 *
 * @category   FreeUch
 * @copyright  Copyright 2009 lordharrdlee(http://www.lordharrdlee.cn)
 * @author     lordharrdlee<lordharrdlee@gmail.com>
 * @version    $Id: bootstrap.php 11 2010-01-14 10:33:41Z lordharrdlee $
 */

getmember();

/**
 * request mod
 */
$mod = trim($_REQUEST["mod"]);
$mod = empty($mod) ? 'default' : $mod;

/**
 * request action
 */
$action = trim($_REQUEST["act"]);
$action = empty($action) ? 'index' : $action;

/**
 * check module is safe
 */
/*$modules = array('tool','admin','power','login','admin_test','ad');
if (!in_array($mod,$modules)) {
	deny();
}*/

/**
 * check if sub mod
 */
$submod = $subCls = $subPath = '';
if (strpos($mod, '_')) {
    $modAry = explode('_', $mod);
    $submod = ucwords($modAry[0]);
    $mod = $modAry[1];
}
$modName = ucwords($mod);
$clsName = 'Action_' . $modName;
if ($submod) {
    $clsName = 'Action_' . $submod . '_' . $modName;
    $subCls = $submod . '_';
    $subPath = $submod . DS;
}

/**
 * load action class
 */
if(!file_exists(FREEUCH_ROOT.'application'.DS.'Action'.DS.$subPath.$modName.'.php')) {
    show404();
}
$serviceObj = new $clsName();
if (!method_exists($serviceObj, $action)) {
    show404();
}

/**
 * check if use model
 */
$modelObject = $serviceObj->getUseModel();
if ($modelObject) {
    $modelCls = 'Model_' . $subCls . $modName;
    if(!file_exists(FREEUCH_ROOT.'application'.DS.'Model'.DS.$subPath.$modName.'.php')) {
        show404();
    }
    $modelObject = new $modelCls();
    $serviceObj->setModel($modelObject);
}

/**
 * set mod
 */
$serviceObj->setMod($mod);
$serviceObj->setSubmod($submod);

/**
 * call action
 */
$serviceObj->$action();
